﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProjectEulerSolutions
{
    /*
      A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.

      Find the largest palindrome made from the product of two 3-digit numbers.

     */
    class Problem4
    {
        public static string Calculate()
        {
            List<int> result = new List<int>();

            for (int i = 999; i >= 100; i--)
            {
                for (int j = 999; j >= 100; j--)
                {
                    if (IsPalindrome(i * j))
                    {
                        Console.WriteLine("{0} * {1} = {2}", i, j, i * j);
                        result.Add(i * j);
                    }
                }
            }

            return result.Max().ToString();
        }

        static bool IsPalindrome(int num)
        {
            string tekst = num.ToString();

            for (int i = 0; i <= Math.Ceiling(tekst.Length / 2.0); i++)
            {
                if (tekst[i] != tekst[tekst.Length - 1 - i])
                    return false;
            }
            return true;
        }
    }
}
